% Note:
% Context: 
% Optimal Choice Problem: Vhat=max_{i}{x_{i}+V_{i}}
% where x_{i} is i.i.d. Gumbel distribution with CDF exp( -exp(-SIG*(x-MU)) )
% MU, SIG: the location and shape parameters of the distribution;
% V: (#obs x #i) matrix;
% Prob: the probability of choosing option i;
% ExpVhat: the expected value of Vhat.
function [varargout]=Logit_Prob(MU,SIG,V)

V_Mid       =   mean(V,2);
V_Diff      =   bsxfun(@minus,V,V_Mid);
EV_Diff     =   exp(SIG*V_Diff);
SumEV_Diff  =   sum(EV_Diff,2);
Prob        =   bsxfun(@rdivide,EV_Diff,SumEV_Diff);

if isempty(MU)
    varargout{1}=   Prob;
else
    MUhat       =   MU+(log(SumEV_Diff)+SIG*V_Mid)/SIG;

    EulerConst  =   0.577215664901533;
    ExpVhat     =   MUhat+EulerConst/SIG;
    
    varargout{1}=   Prob;
    varargout{2}=   ExpVhat;
end